﻿using apiframworkTest.Mapper;
using Autofac;
using Autofac.Integration.Mvc;
using Autofac.Integration.WebApi;
using commonFramwork.CacheManager;
using EF.Framework.Ef;
using My.BLL.boot;
using My.BLL.NewService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;

namespace apiframworkTest.boot
{
    public class AutoFacBootStrapper
    {
        public static void Configure()
        {
            ConfigureAutofacContainer();
            AutoMapperConfiguration.Configure();
        }

        private static void ConfigureAutofacContainer()
        {
            var webApiContainerBuilder = AutofacBootstrapper.Configure();
          //  var commonContainerBuilder = commonFramwork.boot.AutofacBootstrapper.Configure();
            ConfigureWebApiContainer(webApiContainerBuilder);
           // ConfigureWebApiContainer(commonContainerBuilder);
        }

        private static void ConfigureWebApiContainer(ContainerBuilder containerBuilder)
        {
            containerBuilder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            var container = containerBuilder.Build();

            var provider = container.Resolve<ICacheProvider>();
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            commonFramwork.boot.AutofacBootstrapper.SetInstance(provider);
        }
    }
}